
/**
 *  @description 该脚本用来获取用户配置
 */

const { program } = require('commander')

const { createPromptModule } = require('inquirer')

const { exec } = require('child_process')

const prompt = createPromptModule()

const packageMap = new Map([
  ['全部', 'all'],
  ['物联网', 'iot'],
  ['视联网', 'cvs'],
  ['数据中台', 'datacenter'],
  ['可视化', 'view'],
  ['用户权限', 'user']
])

const routes = ['iot', 'cvs', 'datacenter', 'view', 'user']

const promptList = [
  {
    type: 'list',
    message: '是否去掉logo',
    name: 'logo',
    choices: ['yes', 'no']
  },
  {
    type: 'checkbox',
    message: '请选择打包的模块',
    name: 'package',
    choices: ['全部', '物联网', '视联网', '数据中台', '可视化', '用户权限']
  },
  {
    type: 'list',
    message: '请选择打包的平台',
    name: 'platform',
    choices: ['web', 'mac', 'win']
  }
]

prompt(promptList).then((res) => {
  const package = res.package.includes('全部') ? routes : res.package.map(item => packageMap.get(item))

  const userOptionsStr = `--logo=${res.logo} --package=${package.length === 0 ? routes : package} --platform=${res.platform}`
  console.log('重写配置项中......')
  exec('node plugins/build.js ' + userOptionsStr, (error, stdout, stderr) => {
    console.log(error)
    console.log(stdout)
    console.log(stderr)
  })
})
